﻿using System;
using UnityEngine;

namespace UniRx.Triggers
{
	// Token: 0x0200042D RID: 1069
	[DisallowMultipleComponent]
	public class ObservableDestroyTrigger : MonoBehaviour
	{
		// Token: 0x170001C2 RID: 450
		// (get) Token: 0x06001650 RID: 5712 RVA: 0x000615BC File Offset: 0x0005F9BC
		// (set) Token: 0x06001651 RID: 5713 RVA: 0x000615C4 File Offset: 0x0005F9C4
		[Obsolete("Internal Use.")]
		internal bool IsMonitoredActivate { get; set; }

		// Token: 0x170001C3 RID: 451
		// (get) Token: 0x06001652 RID: 5714 RVA: 0x000615CD File Offset: 0x0005F9CD
		// (set) Token: 0x06001653 RID: 5715 RVA: 0x000615D5 File Offset: 0x0005F9D5
		public bool IsActivated { get; private set; }

		// Token: 0x170001C4 RID: 452
		// (get) Token: 0x06001654 RID: 5716 RVA: 0x000615DE File Offset: 0x0005F9DE
		public bool IsCalledOnDestroy
		{
			get
			{
				return this.calledDestroy;
			}
		}

		// Token: 0x06001655 RID: 5717 RVA: 0x000615E6 File Offset: 0x0005F9E6
		private void Awake()
		{
			this.IsActivated = true;
		}

		// Token: 0x06001656 RID: 5718 RVA: 0x000615F0 File Offset: 0x0005F9F0
		private void OnDestroy()
		{
			if (!this.calledDestroy)
			{
				this.calledDestroy = true;
				if (this.disposablesOnDestroy != null)
				{
					this.disposablesOnDestroy.Dispose();
				}
				if (this.onDestroy != null)
				{
					this.onDestroy.OnNext(Unit.Default);
					this.onDestroy.OnCompleted();
				}
			}
		}

		// Token: 0x06001657 RID: 5719 RVA: 0x0006164C File Offset: 0x0005FA4C
		public IObservable<Unit> OnDestroyAsObservable()
		{
			if (this == null)
			{
				return Observable.Return(Unit.Default);
			}
			if (this.calledDestroy)
			{
				return Observable.Return(Unit.Default);
			}
			Subject<Unit> result;
			if ((result = this.onDestroy) == null)
			{
				result = (this.onDestroy = new Subject<Unit>());
			}
			return result;
		}

		// Token: 0x06001658 RID: 5720 RVA: 0x000616A1 File Offset: 0x0005FAA1
		public void ForceRaiseOnDestroy()
		{
			this.OnDestroy();
		}

		// Token: 0x06001659 RID: 5721 RVA: 0x000616A9 File Offset: 0x0005FAA9
		public void AddDisposableOnDestroy(IDisposable disposable)
		{
			if (this.calledDestroy)
			{
				disposable.Dispose();
				return;
			}
			if (this.disposablesOnDestroy == null)
			{
				this.disposablesOnDestroy = new CompositeDisposable();
			}
			this.disposablesOnDestroy.Add(disposable);
		}

		// Token: 0x04000C92 RID: 3218
		private bool calledDestroy;

		// Token: 0x04000C93 RID: 3219
		private Subject<Unit> onDestroy;

		// Token: 0x04000C94 RID: 3220
		private CompositeDisposable disposablesOnDestroy;
	}
}
